package com.negative.activities;

import com.negative.logic.DialogManager;
import com.negative.logic.MenuListener;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;

public class SettingsActivity extends Activity {

	private ImageView menuButton;
	private MenuListener menuListener;
	private Button send;
	private EditText feedbackContent;
	private Activity activity;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.settings_layout);

		initialize();
	}

	private void initialize() {

		activity = this;
		menuListener = new MenuListener(this);
		menuButton = (ImageView) findViewById(R.id.menu_icon);
		feedbackContent = (EditText) findViewById(R.id.feedback_content);
		send = (Button) findViewById(R.id.send_email);

		menuButton.setOnClickListener(menuListener);

		send.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				String content = feedbackContent.getText().toString();
				if (content != null && content.isEmpty() == false) {
					Intent i = new Intent(Intent.ACTION_SEND);
					i.setType("message/rfc822");
					i.putExtra(Intent.EXTRA_EMAIL,
							new String[] { "negative.plus.app@gmail.com" });
					i.putExtra(Intent.EXTRA_SUBJECT, "Feedback from User");
					i.putExtra(Intent.EXTRA_TEXT, content);
					try {
						startActivity(Intent.createChooser(i, "Send mail..."));
					} catch (android.content.ActivityNotFoundException ex) {
						Toast.makeText(SettingsActivity.this,
								"There are no email clients installed.",
								Toast.LENGTH_SHORT).show();
					}
				} else {
					Thread dialogThread = new Thread() {
						public void run() {
							DialogManager.showOKDialog(activity, false, activity.getString(R.string.feedback_error), activity.getString(R.string.missing_content));
						}
					};
					dialogThread.start();
				}
			}
		});
	}

	@Override
	protected void onPause() {
		super.onPause();
		finish();
	}

}